home *** CD-ROM | disk | FTP | other *** search
- /* ModifyReadOnly.c: ModifyReadOnly applet for ProjectDrag
- *
- * A set of applets for drag and drop source control by Tim Maroney.
- * See develop, issue 23 for details.
- *
- * Built on DropShell by Leonard Rosenthol, Stephan Somogyi, and Marshall Clow,
- * and using the MoreFiles utilities by Jim Luther.
- *
- * This software is free, but don't modify and redistribute it without
- * changing the status window to indicate your name and your changes!
- */
-
-
- #include <Errors.h>
-
- #include "DSUserProcs.h"
- #include "SourceServer.h"
- #include "PDDialogs.h"
- #include "Comments.h"
- #include "TasksAndErrors.h"
- #include "FileCancel.h"
-
-
- void ModifyReadOnlyFile(FSSpec *file);
-
-
- /* This routine is called for each file passed in the ODOC event. */
-
- pascal void OpenDoc ( FSSpecPtr myFSSPtr, Boolean opening, Handle userDataHandle )
- {
- #pragma unused ( opening )
- #pragma unused ( userDataHandle )
-
- ModifyReadOnlyFile(myFSSPtr);
- }
-
-
- void ModifyReadOnlyFile(FSSpec *file)
- {
- OSErr err;
- AEDesc command;
- CKIDHandle theCKID;
- Str63 userName;
- Str15 nickname;
- Str255 comment;
-
- TaskStart(2001, 1, file->name, NULL, NULL, NULL);
-
- /* find the user name and initials */
- err = GetUserSettings(userName, nickname, false);
- if (err != noErr)
- {
- if (err != userCanceledErr)
- ErrorAlert(kProjectDragStrings, kNoUserSettings, err);
- gDone = true;
- return;
- }
-
- /* get the CKID */
- err = ExtractCKID(file, &theCKID);
- if (err != noErr)
- {
- RaiseErrorString(kProjectDragStrings, kCantGetCKID, file->name,
- NULL, NULL, NULL);
- return;
- }
-
- /* make sure the file is checked in */
- if ((*theCKID)->writeable || (*theCKID)->modifyReadOnly)
- {
- DisposeHandle((Handle)theCKID);
- RaiseErrorString(kProjectDragStrings, kNoMROPermission, file->name,
- NULL, NULL, NULL);
- return;
- }
-
- /* create a ModifyReadOnly command for SourceServer
- * ModifyReadOnly <file>
- */
- err = CreateCommand(&command, "ModifyReadOnly");
- if (err == noErr)
- err = AddFileNameArg(&command,file);
- if (err != noErr)
- {
- DisposeHandle((Handle)theCKID);
- AEDisposeDesc(&command);
- RaiseErrorNumber(err);
- return;
- }
-
- /* send the command to SourceServer */
- err = SendCommand(&command);
- if (err != noErr)
- {
- DisposeHandle((Handle)theCKID);
- return;
- }
-
- /* get the checkout comment from the user */
- comment[0] = 0;
- if (!GetChangeComment(false, file->name, comment))
- {
- DisposeHandle((Handle)theCKID);
- return;
- }
-
- /* add the checkout comment to the file */
- err = AddCheckoutComment(file, userName, nickname, comment);
- if (err != noErr)
- {
- /* pop the current task and start a new one if user confirms cancel */
- if (!ResTextYesNo(kProjectDragStrings, kMROCommentFailedCancel,
- file->name, NULL, NULL, NULL))
- {
- RaiseErrorNumber(userCanceledErr);
- return;
- }
-
- TaskDone(); /* not really! */
-
- TaskStart(2001, 2, file->name, NULL, NULL, NULL); /* canceling */
- err = FileCancel(file, theCKID);
- DisposeHandle((Handle)theCKID);
- if (err != noErr) return;
- }
- else
- {
- DisposeHandle((Handle)theCKID);
- }
-
- /* modify the label to blue (4) */
- SetFileLabel(file, 4, NULL);
-
- TaskDone();
- }
-
-
- void DoFileMenu(short itemID)
- {
- if ( itemID == 1 )
- SelectFile(); // call file selection userProc
- else
- SendQuitToSelf(); // send self a 'quit' event
- }
-